package com.common.UITags;

import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.common.GlobalPara;

public class PermissionTag extends TagSupport {

	/**
	 * 用这个标签来控制前台的权限操作
	 */
	private static final long serialVersionUID = 1L;
	private String permissionId;

	@Override
	public int doStartTag() throws JspException {
		// 如果有权限则显示继续处理content，否则忽略content
		@SuppressWarnings("unchecked")
		Map<String, String> permap = (Map<String, String>) pageContext.getSession().getAttribute(GlobalPara.BUTTON_PERMAP);
		if (permap!=null && permap.containsKey(permissionId)) {
			return EVAL_BODY_INCLUDE;
		} else {
			return SKIP_BODY;
		}
	}

	@Override
	public int doEndTag() throws JspException {
		return EVAL_PAGE;
	}

	public String getPermissionId() {
		return permissionId;
	}

	public void setPermissionId(String permissionId) {
		this.permissionId = permissionId;
	}
}
